﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized;
public partial class manage_login :AdminPageBase
{
    string checkcode;
    bool boolLoginCheck = false;
    string BackListFile = "index.html";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["Logout"]))
            AdminSessionHelper.UserDetails = null;
        if (Request.Cookies["checkcode"] != null)
        {
            checkcode = Request.Cookies["checkcode"].Value;
        }
    }
    protected void ibtnLogin_Click(object sender, ImageClickEventArgs e)
    {
        if ((String.Compare(checkcode, txtcheckcode.Text, true) != 0))
        {
            lblMessage2.Visible = true;
            return;
        }
        else
        {
            string Account = txtAccountID.Text.Trim();
            string PassWord = txtpwd.Text.Trim();
            if (!string.IsNullOrEmpty(Account) && !string.IsNullOrEmpty(PassWord))
            {
                Login(Account, PassWord);
            }
        }
    }
    private void Login(string Account, string PassWord)
    {
        if (!boolLoginCheck)
        {
            boolLoginCheck = true;
           
            NameValueCollection nvc = new NameValueCollection();
            nvc.Add("LoginID", Account);
            nvc.Add("Password", PassWord);
            bool has = jtDataAccess.User_check(nvc);
            if (has)
            {
                int  userid = jtDataAccess.Admin_Login(nvc);
                if (userid>0)
                {

                    DataSet ds = new DataSet();
                    ds = jtDataAccess.GetUserInfo(userid);
                    AdminSessionHelper.UserDetails = ds.Tables[0].Rows[0];
                    if (!string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
                        Response.Redirect(Request.QueryString["ReturnUrl"]);
                    else
                        Response.Redirect(BackListFile);
                }
                else

                    JsHelper.TopAlertRedirect("此账户已被禁用，不能登录，请联系系统管理员！", "login.aspx", this.Page);
            }
            else
                JsHelper.TopAlertRedirect("用户名或密码不正确，登录失败！", "login.aspx", this.Page);
        }
    }
    protected void lbtnChangeimge_Click(object sender, EventArgs e)
    {
       
        Image2.ImageUrl = "imgvil.aspx";
        if (Request.Cookies["checkcode"] != null)
        {
            checkcode = Request.Cookies["checkcode"].Value;
        }
    }
    protected void ibtnreset_Click(object sender, ImageClickEventArgs e)
    {
        txtAccountID.Text = "";
        txtcheckcode.Text = "";
        txtpwd.Text = "";
    }

}
